package com.hspedu.Test;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/12
 * @time 20:32
 */
@SuppressWarnings("all")
public class Test {

    private static int number = 0;
    private static final ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                threadLocal.set(number);
                for (int i = 0; i < 1000; i++) {
                    threadLocal.set(threadLocal.get() + 1);
                    System.out.println("t1----:" + threadLocal.get());
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                threadLocal.set(number);
                for (int i = 0; i < 1000; i++) {
                    threadLocal.set(threadLocal.get() + 1);
                    System.out.println("t2----:" + threadLocal.get());
                }
            }
        });
        t1.start();
        t2.start();

    }
}
